package validate;

import lombok.Builder;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import org.junit.Test;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * @author jiangwz
 * @create 2021/7/29.
 */
public class ValidateTests {

    @Test
    public void test03(){
        OrderReq build = OrderReq.builder().orderId(0L).build();
        ValidatorUtil.validateObject(build);
    }

    @Test
    public void test02(){
        Req build = Req.builder().msg("1111").person(
                Person.builder().id(1L).name("zs").build()
        ).personList(Arrays.asList(
                Person.builder().id(2L).name("ls").build()
        )).build();

        ValidatorUtil.validateObject(build);
    }

    @Test
    public void test01(){
        ValidatorUtil.validateObject(null);
    }

}

@Data
@Builder
class OrderReq{

    @Range
    @Min(1)
    @NotNull
    private Long orderId;

}

@Data
@Builder
class Req{

    @NotNull(message = "msg不能为空")
    private String msg;

    @Valid
    @NotNull(message = "person不能为空")
    private Person person;

    @Valid
    @NotNull(message = "personList不能为空")
    private List<Person> personList;
}

@Builder
@Data
class Person{
    @NotNull(message = "用户id不能为空")
    private Long id;
    @NotNull(message = "用户名称不能为空")
    private String name;

}